/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package presentation;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author quirino
 */
public class PUtility {
    private JButton button;
    private Icon but_icon;
    private Icon but_over_icon;
    private Icon but_pressed_icon;
    private String text_button;
    private JLabel but_label;
    private Icon but_textlabel_icon;

    public PUtility(){}

    public JButton createButtonPersonalizzato(JButton button, String button_icon, String button_over_icon, String button_pressed_icon, String button_text_icon){
        this.but_icon= new ImageIcon(button_icon);
        if(button_over_icon!=null) this.but_over_icon= new ImageIcon(button_over_icon);
        else this.but_over_icon= null;
        if(button_pressed_icon!=null) this.but_pressed_icon= new ImageIcon(button_pressed_icon);
        else this.but_pressed_icon= null;
        this.button= button;
        this.text_button= this.button.getText();
        if(button_text_icon!=null)this.but_textlabel_icon= new ImageIcon(button_text_icon);
        else this.but_textlabel_icon= null;
        this.initButton();
        return button;
    }
    public void initButton(){
        this.button.setIcon(this.but_icon);
        this.button.setText("");
        this.button.setPressedIcon(this.but_pressed_icon);
        this.button.setRolloverIcon(this.but_over_icon);
        this.button.setBorderPainted(false);
        this.button.setBorder(null);
        this.button.setOpaque(true);
        this.button.setMargin(new Insets(0, 0, 0, 0));
        this.button.setContentAreaFilled(false);
        this.button.setCursor(Cursor.getPredefinedCursor (Cursor.HAND_CURSOR));
        this.button.setFocusPainted(false);
        this.button.setBounds(button.getBounds().x, button.getBounds().y, but_icon.getIconWidth()+20, but_icon.getIconHeight()+20);
        this.initTextButton();
    }
    public void initTextButton(){
        this.but_label = new JLabel();
        this.but_label.setText(this.text_button);
        this.button.setLayout(new FlowLayout());
        this.button.add(this.but_label);
        this.but_label.setFont(new java.awt.Font("Verdana",Font.BOLD,14));
        this.but_label.setForeground(Color.WHITE);
        if(this.but_textlabel_icon!=null) this.but_label.setIcon(this.but_textlabel_icon);
    }
    public String getText_button() {
            return text_button;
    }
    public void setText_button(String text_button) {
            this.text_button = text_button;
    }
    public JLabel getBut_label() {
            return but_label;
    }
    public void setBut_label(JLabel but_label) {
            this.but_label = but_label;
    }
    public Icon getBut_textlabel_icon() {
            return but_textlabel_icon;
    }
    public void setBut_textlabel_icon(Icon but_textlabel_icon) {
            this.but_textlabel_icon = but_textlabel_icon;
    }
    public JButton getButton() {
            return button;
    }
    public void setButton(JButton button) {
            this.button = button;
    }
    public Icon getBut_icon() {
            return but_icon;
    }
    public void setBut_icon(Icon but_icon) {
            this.but_icon = but_icon;
    }
    public Icon getBut_over_icon() {
            return but_over_icon;
    }
    public void setBut_over_icon(Icon but_over_icon) {
            this.but_over_icon = but_over_icon;
    }

    public JPanel removePaddingPanelFlow(JPanel pa){
        ((FlowLayout) pa.getLayout()).setHgap(0);
        ((FlowLayout) pa.getLayout()).setVgap(0);
        return pa;
    }
}
